|
|
|
| Table A.9 Scope of Variables. | | Scope | Variable Declared In: | Visibility | | Procedure level | Event procedure, sub, function, or method | Visible in the procedure in which its declared | | Form level, Module level | Declarations section of a form or module (FRM, BAS, or CLS) | Visible in every procedure in the form or code module | | Global/public level | Declarations section of a code module (BAS using Global keyword) | Always visible |
|
|
|
|
|
|
In a Visual Basic application, only use global variables when theres no other convenient way to share data between forms. You should use a property on a form instead of using global variables. |
|
|
|
|
|
|
|
|
If you must use global variables, its good practice to declare all of them in a single module and group them by function. Give the module a meaningful name that indicates its purpose, such as GLOBAL.BAS. |
|
|
|
|
|
|
|
|
With the exception of global variables, procedures and functions should only operate on objects that are passed to them. Global variables that are used in routines should be identified in the general comment area at the beginning of the routine. In addition, you should pass arguments to subs and functions using ByVal, unless you explicitly want to change the value of the passed argument. |
|
|
|
|
|
|
|
|
Write modular code whenever possible. For example, if your application displays a dialog box, put all the controls and code required to perform the dialog boxs task in a single form. This helps keep the applications code organized into useful components and minimizes its runtime overhead. |
|
|
|
|
|
|
|
|
Programming standards can make the job of the maintenance programmer much easier. Because 90 percent of the time youll be the maintenance programmer, you should try to follow some programming standards when designing your applications. Programming standards are absolutely essential in a multiprogrammer shop. |
|
|
|
|
|